package ruifeng.zcj.dig.ui.forum.category;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewAdapter;
import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewHolder;
import cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper;
import ruifeng.zcj.dig.R;
import ruifeng.zcj.dig.groble.FragmentArgs;
import ruifeng.zcj.dig.ui.base.RefreshRecyclerFragment;
import ruifeng.zcj.dig.ui.forum.category.bean.FirstGrade;
import ruifeng.zcj.mybase.base.utils.GlideUtil;

/**
 * 一级板块
 * Created by Administrator on 2016/10/19 0019.
 */
public class FirstGradeFragment extends RefreshRecyclerFragment {

    private List<FirstGrade> mFirstGrades;

    @Override
    protected void initFragmentConfig(View view) {
        super.initFragmentConfig(view);

        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

    }

    @Override
    protected String getCacheKeyPrefix() {
        return "dlkfjdlfk";
    }

    @Override
    protected BGARecyclerViewAdapter getAdapter() {
        return new MomentAdapter(recyclerView);
    }

    @Override
    public void onRVItemClick(ViewGroup parent, View itemView, int position) {
        FragmentArgs args = new FragmentArgs();
        args.add("grades",mFirstGrades.get(position));
        args.add("postion",position);
        EventBus.getDefault().post(args);
    }


    @Override
    public boolean onRVItemLongClick(ViewGroup parent, View itemView, int position) {
        return false;
    }

    @Override
    protected void onUserVisible() {

    }


    /****
     * 网络请求数据具体的子类实现
     **/
    protected void sendRequestData() {
        mMomentAdapter.clear();
        mFirstGrades = FirstGrade.getGrade();
        mMomentAdapter.addNewData(mFirstGrades);
    }


    /***
     * 不显示加载更多
     **/
    @Override
    protected boolean OnLoadingMore() {
        return false;
    }


    @Override
    protected long getAutoRefreshTime() {
        // 最新商品分类两小时刷新一次
        return 2 * 60 * 60;
    }


    public class MomentAdapter extends BGARecyclerViewAdapter<FirstGrade> {

        int[] resImags = {
                R.drawable.talk_h,R.drawable.recruit_h,R.drawable.parts_h,
                R.drawable.consultation_h,R.drawable.share_h,
        };
        public MomentAdapter(RecyclerView recyclerView) {
            super(recyclerView, R.layout.fragment_category_item);
        }

        @Override
        public void fillData(BGAViewHolderHelper helper, int position, FirstGrade moment) {
            /*if (TextUtils.isEmpty(moment.content)) {
                helper.setVisibility(R.id.tv_item_moment_content, View.GONE);
            } else {
                helper.setVisibility(R.id.tv_item_moment_content, View.VISIBLE);
                helper.setText(R.id.tv_item_moment_content, moment.content);
            }*/
            helper.setImageResource(R.id.category_img,resImags[position]);
          //  helper.getImageView(R.id.category_img).setImage;

          //  GlideUtil.loadImage(mContext, String.format("http://kw.runfkj.com%s", moment.getPhoto()), imageView);

            helper.setText(R.id.category_title, "" + moment.getName());
            helper.setText(R.id.category_content, "" + moment.getContent());

          /*
            /*TextView postingsname = helper.getView(R.id.forum_fragment_item_text_title);

            BGANinePhotoLayout ninePhotoLayout = helper.getView(R.id.npl_item_moment_photos);

            ninePhotoLayout.init(MomentListActivity.this);
            ninePhotoLayout.setDelegate(MomentListActivity.this);
            ninePhotoLayout.setData(moment.photos);*/
        }

        @Override
        public void onViewRecycled(BGARecyclerViewHolder holder) {
            super.onViewRecycled(holder);

           /* BGANinePhotoLayout ninePhotoLayout = holder.getViewHolderHelper().getView(R.id.npl_item_moment_photos);
            ninePhotoLayout.init(null);
            ninePhotoLayout.setDelegate(null);*/
        }
    }

}
